﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLHD.BLL;

namespace QLHD.DAL
{
    public class CTNhapTho_DB
    {
        public static DataTable SelectAllNhap_Tho()
        {
            using(SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spSelectAll_CTNhapNLTho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spSelectAll_CTNhapNLTho", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static void InsertCTNhap_Tho(CTNhapTho newCTNhapTho)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spThemCT_NhapNL_Tho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spThemCT_NhapNL_Tho", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaNhapNL", newCTNhapTho.MaNhapNL);
                command.Parameters.AddWithValue("@NgayThang", newCTNhapTho.Ngaythang);
                command.Parameters.AddWithValue("@MaNX", newCTNhapTho.Manx);
                command.Parameters.AddWithValue("@MaLo", newCTNhapTho.Malo);
                command.Parameters.AddWithValue("@MaNhom", newCTNhapTho.Manhom);
                command.Parameters.AddWithValue("@DienGiai", newCTNhapTho.Diengiai);
                command.Parameters.AddWithValue("@DonGia", newCTNhapTho.Dongia);
                command.Parameters.AddWithValue("@KL_Nhap", newCTNhapTho.Kl_nhap);
                command.Parameters.AddWithValue("@MaNCC", newCTNhapTho.Mancc);
                command.Parameters.AddWithValue("@MaKho", newCTNhapTho.Makho);
                command.ExecuteNonQuery();

            }           
        }
        public static void UpdateCTNhap_Tho(string oldMaNhapNL, CTNhapTho newCTNhapTho)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spCapNhatKho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spCapNhatKho", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaNhapNL", oldMaNhapNL);
                command.Parameters.AddWithValue("@NgayThang", newCTNhapTho.Ngaythang);
                command.Parameters.AddWithValue("@MaNX", newCTNhapTho.Manx);
                command.Parameters.AddWithValue("@MaLo", newCTNhapTho.Malo);
                command.Parameters.AddWithValue("@MaNhom", newCTNhapTho.Manhom);
                command.Parameters.AddWithValue("@DienGiai", newCTNhapTho.Diengiai);
                command.Parameters.AddWithValue("@DonGia", newCTNhapTho.Dongia);
                command.Parameters.AddWithValue("@KL_Nhap", newCTNhapTho.Kl_nhap);
                command.Parameters.AddWithValue("@MaNCC", newCTNhapTho.Mancc);
                command.Parameters.AddWithValue("@MaKho", newCTNhapTho.Makho);
                command.ExecuteNonQuery();
            }
        }
        public static void DeleteCTNhap_Tho(string maNhapNL) 
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spXoaCT_NhapNL_Tho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spXoaCT_NhapNL_Tho", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaNhapNL", maNhapNL);
                command.ExecuteNonQuery();

            }
        }
    }
}
